import java.io.*;
import java.util.*;

public class Restaurant implements PersistentObject, Serializable {

  private String name;
  private String address;
  private String zipCode;
  private String foodType;
  private double rating; // avg rating
  private Preferences preferences;
  private Vector<Double> ratings; // all ratings

  /*
   * Proof:
   * 	Precondition: None
   * 	Postcondition: Restaurant object is returned with a set name
   * 	Method calls set methods are totally correct.
   * 	There are no loops therefore it will terminate.
   */
  public Restaurant(String name) {
    setName(name);
    setAddress(null);
    setZipCode(null);
    setFoodType(null);
    setPreferences(null);
    ratings = new Vector<Double>();
  }

  /*
   * Proof: 
   * 	Precondition: None
   * 	Postcondition: Restaurant object is returned with a set name,
   * 		address, zip code, food type, and preferences
   * 	Method calls set methods are totally correct.
   * 	There are no loops therefore it will terminate.
   */
  public Restaurant(String name, String address, String zipCode, String fType, Preferences prefs) {
    setName(name);
    setAddress(address);
    setZipCode(zipCode);
    setFoodType(fType);
    setPreferences(prefs);
    ratings = new Vector<Double>();
  }

  /* 
   * Proof: Get Methods
   * 	Precondition: None
   * 	Postcondition: String is returned
   * 	Method returns a String.
   * 	No loops therefore the method will terminate
   * Proof: Set Methods
   * 	Precondition: None
   * 	Postcondition: Object is set
   * 	Method sets the object with the parameter. 
   * 	No loops therefore the method will terminate
   */
  public void setName(String n) {name = n;}
  public String getName() {return name;}
  public void setAddress(String a) {address = a;}
  public String getAddress() {return address;}
  public void setFoodType(String type) {foodType = type;}
  public String getFoodType() {return foodType;}
  public void setZipCode(String zip) {zipCode = zip;}
  public String getZipCode() {return zipCode;}
  public double getRating() {return rating;}
  public void addRating(double r) {ratings.add(new Double(r)); setRating();}
  public void setPreferences(Preferences prefs) {preferences = prefs;}
  public Preferences getPreferences() {return preferences;}

  /*
   * Proof:
   * 	Preconditions: None
   * 	Postconditions: Average of ratings are set
   * 	Method sums up the ratings in a for loop. Loop ends when all 
   * 	ratings have been added then is divided by the number of ratings. 
   * 	Therefore, the method will terminate.
   */
  public void setRating() {
    double sum = 0.0, average = 0.0;
    for (int i=0; i < ratings.size(); i++) {
      sum += ratings.elementAt(i).intValue();
    }
    rating = (sum/(ratings.size()));
  }

@Override
public String key() {
	return name;
}
}
